//
//  YRJCityGoFreedomWebViewController.m
//  YanRenjie
//
//  Created by dllo on 15/10/30.
//  Copyright (c) 2015年 yanrenjie. All rights reserved.
//

#import "YRJCityGoFreedomWebViewController.h"
#import "YRJTripHeader.h"
#import "YRJSingleton.h"

@interface YRJCityGoFreedomWebViewController ()<UIWebViewDelegate, UMSocialUIDelegate>
@property(nonatomic, retain)NSString *strURL;
@property(nonatomic, retain)MBProgressHUD *hud;
@end

@implementation YRJCityGoFreedomWebViewController

{
    // 风火轮
    UIActivityIndicatorView *acView;
}

- (void)dealloc {
    [_idNumber release];
    
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBar.translucent = NO;
    self.view.backgroundColor = [UIColor whiteColor];
    
    UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];
    [self.view addSubview:webView];
    webView.delegate = self;
    webView.scalesPageToFit = YES;
    [webView release];

    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"分享" style:UIBarButtonItemStylePlain target:self action:@selector(shareAction:)];
    
    self.hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    self.hud.labelText = @"Loading...";
    
    acView = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 0, (32.0 / 375) * WIDTH, (32.0 / 375) * WIDTH)];
    acView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;
    acView.center = self.view.center;
    [acView release];
    //http://open.qyer.com/qyer/discount/tickets_freewalker?client_id=qyer_ios&client_secret=cd254439208ab658ddf9&count=20&id=55&order=2&page=1&product_type=1016%2C1018%2C1020&time=1&track_app_channel=App%2520Store&track_app_version=6.8&track_device_info=iPhone%25204%28ChinaMobile%2CChinaUnicom%29&track_deviceid=AB5B28ED-8670-4190-873A-F09EFE3EB3E8&track_os=ios%25207.1.2&type=2&v=1
    self.strURL = [NSString stringWithFormat:@"%@%@%@", @"http://open.qyer.com/qyer/discount/tickets_freewalker?client_id=qyer_ios&client_secret=cd254439208ab658ddf9&count=20&id=", self.idNumber, @"&order=2&page=1&product_type=1016%2C1018%2C1020&time=1&track_app_channel=App%2520Store&track_app_version=6.8&track_device_info=iPhone%25204%28ChinaMobile%2CChinaUnicom%29&track_deviceid=AB5B28ED-8670-4190-873A-F09EFE3EB3E8&track_os=ios%25207.1.2&type=2&v=1"];
    
    NSURL *url = [NSURL URLWithString:self.strURL];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [webView loadRequest:request];
    
    
}

- (void)shareAction:(UIButton *)button {
//    if ([YRJSingleton shareSingleton].isLogin) {
        [UMSocialSnsService presentSnsIconSheetView:self
                                             appKey:@"563ab1eee0f55a83c5005570"
                                          shareText:self.strURL
                                         shareImage:nil
                                    shareToSnsNames:[NSArray arrayWithObjects:UMShareToTencent,nil]
                                           delegate:self];
//    } else {
//        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"请先登录" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
//        [alert show];
//    }
}

-(void)didFinishGetUMSocialDataInViewController:(UMSocialResponseEntity *)response
{
    //根据`responseCode`得到发送结果,如果分享成功
    if(response.responseCode == UMSResponseCodeSuccess)
    {
        //得到分享到的微博平台名
        NSLog(@"share to sns name is %@",[[response.data allKeys] objectAtIndex:0]);
    }
}

- (void)webViewDidFinishLoad:(UIWebView *)webView {
    self.hud.hidden = YES;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
